use std::fmt;
use std::error::Error;

#[derive(Debug)]
pub enum ProtoError {
    MailboxClosed,
    MailboxFull,
    ActorNotFound,
    // 其他错误类型...
}

impl fmt::Display for ProtoError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl std::error::Error for ProtoError {}

#[derive(Debug, Clone)]
pub enum SendError {
    MailboxFull,
    CircuitBreakerOpen,
    ActorStopped,
    SystemError(String),
}

impl fmt::Display for SendError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SendError::MailboxFull => write!(f, "Mailbox is full"),
            SendError::CircuitBreakerOpen => write!(f, "Circuit breaker is open"),
            SendError::ActorStopped => write!(f, "Actor is stopped"),
            SendError::SystemError(msg) => write!(f, "System error: {}", msg),
        }
    }
}

impl Error for SendError {}

#[derive(Debug)]
pub enum SpawnError {
    ActorPanicked,
    InvalidProps,
    // 其他错误类型...
}

impl fmt::Display for SpawnError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl std::error::Error for SpawnError {}

#[derive(Debug)]
pub enum WorkflowError {
    Io(std::io::Error),
    Serialization(bincode::Error),
    NodeNotFound(String),
    InvalidState,
    // 其他错误类型...
}

impl fmt::Display for WorkflowError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl std::error::Error for WorkflowError {}

#[derive(Debug)]
pub enum SerializationError {
    EncodingError(String),
    DecodingError(String),
    NoSerializerFound,
    TypeMismatch,
    InvalidFormat(String),
}

impl fmt::Display for SerializationError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SerializationError::EncodingError(msg) => write!(f, "Encoding error: {}", msg),
            SerializationError::DecodingError(msg) => write!(f, "Decoding error: {}", msg),
            SerializationError::NoSerializerFound => write!(f, "No serializer found for type"),
            SerializationError::TypeMismatch => write!(f, "Type mismatch during serialization/deserialization"),
            SerializationError::InvalidFormat(msg) => write!(f, "Invalid format: {}", msg),
        }
    }
}

impl Error for SerializationError {} 